define(['template','jcookie','jquery'], (template,jcookie) => {
	class Header {
		constructor() {
			this.loadHeader().then(() => {
				this.loge()
				this.calcCartCount()
				this.Uname()
			})
		}
		
		loadHeader() {
			return new Promise((resolve) => {
				$('header').load('/html/modules/header.html', () => {
					resolve()
				})
			})
		}

		loge() {
			return new Promise((resolve) => {
				$.get('http://www.xiongmaoyouxuan.com/api/tabs?sa=', (resp) => {
					if (resp.code === 200) {
						this.data = resp.data
						$('#titledoem').html(template('titledoemTemplate', { ...this.data
						}))
						resolve()
					}
				})
			})
		}

		calcCartCount() {
			let count = 0
			let cart = localStorage.getItem('cart')
			if (cart) {
				cart = JSON.parse(cart)
				count = cart.reduce((num, shop) => {
					return num + shop.count
				},0)
			}
			$('.ToCart').html(count)
		}
		
		Uname(){
			const name = $.cookie('name')
			if(name){
				$('.ffff').css('display','block')
				$('.Uname').html(name)
			}else{
				$('.ffff').css('display','none')
			}
		}
	}
	return new Header()
})
